<template>
  <div>
    <el-dialog :title="dialogColumns.title" :visible.sync="dialogColumns.dialogFormVisible">
      <el-form :model="value" v-bind="dialogColumns">
       <template v-for="(item,index) in dialogColumns.columns">
         <el-form-item v-if="item.type==='text'" :key="index" v-bind="item">
          <el-input v-model="value[item.prop]" v-bind="item"></el-input>
        </el-form-item>
        <el-form-item v-else-if="item.type==='email'" :key="index" v-bind="item">
          <el-input v-model="value[item.prop]" v-bind="item">
            <template slot="append">@imooc.com</template>
          </el-input>
        </el-form-item>
        <el-form-item  v-else-if="item.type==='select'" :key="index" v-bind="item">
          <el-select v-model="value[item.prop]" v-bind="item">
            <el-option v-for="(item,index) in item.options" :key="index" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-bind="item" v-else-if="item.type==='cascader'" :key="index">
            <el-cascader v-model="value[item.prop]" :options="item.options" :props="{ checkStrictly: true,value:'_id',label:'deptName' }" clearable></el-cascader>
        </el-form-item>
       </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleReset">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props : {
    value : {
      type : Object,
      defalut : {}
    },
    dialogColumns : {
      type : Object,
      defalut : {}
    },
    resertDialog:Function
  },
  methods: {
    handleSubmit(){
      if(this.value.userId) {
        this.$emit('handleSubmit', 'edit')
      }else {
        this.$emit('handleSubmit','add')
      }
    },
    handleReset(){
      this.resertDialog()
    }
  },
}
</script>

<style>

</style>
